#include "MsgUtil.h"

int getMsgQueue(){
    //获取key
    key_t key=ftok(PATHNAME_BOA_MAIN,PROCESS_ID_BOA_MAIN);
    if (key==-1)
    {
        perror("fotk():");
        return -1;
    }
    //获取队列返回消息队列id
    int mqId=msgget(key,IPC_CREAT|0666);
    if (mqId==-1)
    {
        perror("msgget():");
        return -1;
    }
    return mqId;
}
//发消息
int sendMsg(int mqId,Message* msg,int msgSize){
    int ret=msgsnd(mqId,msg,msgSize,0);
    if (ret==-1)
    {
        perror("send msg error:");
        return -1;
    }
    return ret;
}
//收信息
int recvMsg(int mqId,Message* msg,int msgSize){
    int ret=msgrcv(mqId,msg,msgSize,0,0);
    if (ret==-1)
    {
        perror("recive msg error:");
        return -1;
    }
    return ret;
}